package 校招笔试.karl网模拟.模拟821;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/8/25 15:14
 */
public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        new Main().solve1();
    }


    public void solve1(){
        int n = sc.nextInt();
        sc.nextLine();
        Integer nums[] = new Integer[n];
        int last = 0,count = 0;
        for(int i = 0;i < n;i++){
            nums[i] = sc.nextInt();

        }
        if(check(nums)){
            System.out.println(count);
            return ;
        }
        while(!check(nums)){
            List<Integer> list = new ArrayList<>();
            last = 0;
            for(int i = 0;i < nums.length;i++){
                if(nums[i] >= last){
                    list.add(nums[i]);
                }
                last = nums[i];
            }
            count++;
            nums = list.toArray(new Integer[0]);
        }
        System.out.println(count);
    }

    private boolean check(Integer[] nums) {
        for(int i = 1;i < nums.length;i++){
            if(nums[i] < nums[i - 1]){
                return false;
            }
        }
        return true;
    }


    // 蛇形矩阵
    public void solve2(){
        int n = sc.nextInt(),m = sc.nextInt();

        int arr[][] = new int[n][m];
        int col = 1;
        int row = 1;
        arr[0][0] = 1;
        for(int i = 1;i < m;i++){
            arr[0][i] = arr[0][i - 1] + row++;
        }
        for(int j = 1;j < n;j++){
            for(int i = 0;i < m;i++){
                arr[j][i] = arr[j - 1][i] + i + 2;
            }
        }

    }



}
